/**
 *
 * Copyright  2011 Nokia Corporation.
 * tuomo.hirvonen@digia.com
 *
 */


#ifndef __THEGAME__
#define __THEGAME__

#include "SpriteBatch.h"
#include "thelevel.h"
#include "themenu.h"
#include "particlesystem.h"


#define KINETIC_SWEEP_TIME 0.25f            // How many seconds the sweep must be to be accepted.
#define KINETIC_MOVEMENT_POWER 0.75         // larger=more speed
#define KINETIC_STOP_SPEED 700.0f           // pixels/second speed where kinetic - movement stops
#define CLICK_RADIUS (28.0f)                // What is the radius between press/release when clicking
#define BLOCK_SIZE 96
#define LONG_CLICK_TIME 0.25f
#define CAMERA_LIMIT_STRENGTH 10.0f          // How fast the camera scrols back when you try to go too far from the level

    // Rendering
#define FONT_X_INC_MUL 0.8f


struct GameTextures {
    int playerTexture;
    int bgTexture;
    int fontTexture;
    int levelTexture;
    int iconTexture;
    int slidersTexture;
    int logoTexture;
};

class TheGame {
public:
    TheGame( SpriteBatch *sbatch );
    ~TheGame();

    bool update( const float frameDelta );
    void render();
    void press( float x, float y);
    void move( float x, float y );
    void release( float x, float y);
    void cancelPress();         // for multitouch-support,...

    TheLevel *getLevel() { return level; }
    SpriteBatch *getSpriteBatch() { return spriteBatch; }
    GameTextures &getGameTextures() { return gameTextures; }
    ParticleSystem *getParticleSystem() { return particles; }
    ParticleSprayType *getExplosionSpray() { return &explosionSpray; }
    ParticleSprayType *getSparkleSpray() { return &sparkleSpray; }
    ParticleSprayType *getStarSpray() { return &starSpray; }

    void writeText( SpriteBatch *batch, const char *text,  float x, float y, float size, float *color = 0);

    bool launchOviClient;           // polled by the main window.

protected:
    float waitBeforeCreatingMenu;
    float crossFaderCounter;
    unsigned char crossFaderState;
    int crossFaderString;
    void resetCrossFader();

    void renderMainScreen();
    void renderHud();
    void newGame();

        // when raised, update will return false to indicate  we should quit.
    bool exitFlag;

        // Scrollbars are displayed when the camera is moving.
    float scrollBarVisibility;

    bool closeButtonActivated;
    float finishedCounter;
    int difficulty;
    float gameTime;
    float pressDownPos[2];
    float exPressPos[2];
    float potentialMove[2];
    bool pressing;
    float pressTime;
    bool longClickPossible;
    bool clickPossible;

    float cameraPos[2];
    float tempAngle;


    GameTextures gameTextures;
    SpriteBatch *spriteBatch;

    // Particle types
    ParticleSprayType explosionSpray;
    ParticleSprayType starSpray;
    ParticleSprayType sparkleSpray;

        // Game objects
    TheLevel *level;
    TheMenu *menu;
    ParticleSystem *particles;
};




#endif
